package com.waitingresult.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.handlers.StrictFill;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.waitingresult.common.base.domain.BaseEntity;
import com.waitingresult.common.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * All right reserved,Designed By WangShuai
 *
 * @author : WangShuai
 * @version : V1.0
 * @ClassName : MetaObjectHandlerConfig
 * @Description : Mybatis-Plus 自动填充功能
 * @date : 2021/9/10 14:31
 */
@Component
@Primary
@Slf4j
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    //TODO  修改字段 没有补全 , 缺少当前人

    @Override
    public void insertFill(MetaObject metaObject) {
        int nowTime = TimeUtils.getNowTime();
//        this.strictInsertFill(metaObject, "status", Boolean.class, true);
        this.strictInsertFill(metaObject, "createdTime", Integer.class, nowTime);
        this.strictInsertFill(metaObject, "updatedTime", Integer.class, nowTime);
        this.strictInsertFill(metaObject, "deletedTime", Integer.class, nowTime);
        this.strictInsertFill(metaObject, "deletedFlag", Boolean.class, false);
        this.strictInsertFill(metaObject, "revision", Integer.class, 1);
    }


    @Override
    public void updateFill(MetaObject metaObject) {
        int nowTime = TimeUtils.getNowTime();
        this.strictInsertFill(metaObject, "updatedTime", Integer.class, nowTime);
    }
}
